package gui.menu.file;

import data.DataVector;
import dataExport.Exporter;
import org.pushingpixels.flamingo.api.common.JCommandButton;
import org.pushingpixels.flamingo.api.common.icon.EmptyResizableIcon;
import org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntrySecondary;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * User: Szymon Kudzia
 * Date: 30.04.13
 * Time: 14:57
 */
public class ExporterItem extends RibbonApplicationMenuEntrySecondary implements ActionListener {
	protected final JFileChooser fc = new JFileChooser();

	protected Exporter exporter;

	public ExporterItem(Exporter exporter) {
		super(new EmptyResizableIcon(10), exporter.getName(), null, JCommandButton.CommandButtonKind.ACTION_ONLY);

		this.mainActionListener = this;

		this.exporter = exporter;

		fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	}

	public void actionPerformed(ActionEvent e) {
		int returnVal = fc.showOpenDialog(null);

		if (returnVal == JFileChooser.APPROVE_OPTION) {

			exporter.export(
					fc.getSelectedFile().getAbsolutePath(),
					DataVector.getInstance().getEntityList()
			);

			JOptionPane.showMessageDialog(null, "Exporting finished!");
		}
	}

}
